package com.system.manager.modules.development.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.manager.common.entity.Result;
import com.system.manager.common.exception.SysException;
import com.system.manager.modules.development.entity.DeveContract;
import com.system.manager.modules.development.entity.DeveRecord;
import com.system.manager.modules.development.mapper.DeveRecordMapper;
import com.system.manager.modules.development.service.IDeveRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yxp
 * @since 2021-11-17
 */
@Service
public class DeveRecordServiceImpl extends ServiceImpl<DeveRecordMapper, DeveRecord> implements IDeveRecordService {
    @Autowired
    private  DeveRecordMapper  deveRecordMapper;

    @Override
    public void insertRecord(DeveRecord deveRecord) {
        //插入项目记录
        try {
            deveRecordMapper.insert(deveRecord);
        } catch (Exception e) {
            throw new SysException();
        }

    }

    @Override
    public Result selectAllRecord(Integer page, Integer size, Integer id) {
        IPage<DeveRecord> iPage = new Page<>(page,size);
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if(id != null){
            queryWrapper.eq("id",id);
        }
        //分页查询
        page(iPage,queryWrapper);
        List<DeveRecord> records = iPage.getRecords();
        int total = (int) iPage.getTotal();
        return Result.ok(records,total);
    }

    //根据id查找关键实践，根据查询返回结果判断是否通过付款
//    @Override
//    public Result selectAllRecord(int id) {
//        QueryWrapper<DeveRecord> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("id", id);
//        List<DeveRecord> deveRecord = deveRecordMapper.selectList(queryWrapper);
//        return deveRecord;
//
//    }
}
